#version 320 es

#define MAX_BONE 100

layout (location = 0) in vec3 inPos;
layout (location = 1) in vec3 inNor;
layout (location = 2) in vec2 inUV;
layout (location = 3) in ivec4 inBoneIndex;
layout (location = 4) in vec4 inBoneWeights;

layout (location = 5) uniform mat4 CameraVPMatrix;
layout (location = 6) uniform mat4 ModelMatrix;
layout (location = 7) uniform mat4 BoneTransformList[MAX_BONE];

struct VSOut
{
    vec3 nor_vec;
    vec3 w_pos;
    vec2 uv;
};

out VSOut vsout;

void main()
{
    mat4 BoneTransformMatrix = BoneTransformList[inBoneIndex.x] * inBoneWeights.x;
    BoneTransformMatrix += BoneTransformList[inBoneIndex.y] * inBoneWeights.y;
    BoneTransformMatrix += BoneTransformList[inBoneIndex.z] * inBoneWeights.z;
    BoneTransformMatrix += BoneTransformList[inBoneIndex.w] * inBoneWeights.w;

    vec4 skinnedPos = BoneTransformMatrix * vec4(inPos, 1.0);

    gl_Position = CameraVPMatrix * ModelMatrix * skinnedPos;
    vsout.nor_vec = inNor;
    highp vec4 world_pos = ModelMatrix * skinnedPos;
    vsout.w_pos = world_pos.xyz;
    vsout.uv = inUV;
}